package Form;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import Control.Shop_Product_Controller;


@SuppressWarnings("serial")
public class Shop_Order_Form extends JPanel {
	private JLabel lblShoppingCart;
	private JPanel options;
	private JScrollPane orders;
	private JPanel products;
	private Main parser;
	private Shop_Product_Controller control;
	private JLabel lblTotalPrice;
	private JLabel totalPrice;
	private JButton btnCheckout;
	public Main getParser() {
		return parser;
	}

	public void setParser(Main parser) {
		this.parser = parser;
	}

	public Shop_Product_Controller getControl() {
		return control;
	}

	public void setControl(Shop_Product_Controller control) {
		this.control = control;
	}

	public Shop_Order_Form(Main parser) {
		setParser(parser);
		setControl(new Shop_Product_Controller(this));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{155, 191, 80, 126, -18, 0};
		gridBagLayout.rowHeights = new int[]{0, 51, 57, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		GridBagConstraints gbc_lblShoppingCart = new GridBagConstraints();
		gbc_lblShoppingCart.fill = GridBagConstraints.HORIZONTAL;
		gbc_lblShoppingCart.gridwidth = 2;
		gbc_lblShoppingCart.insets = new Insets(5, 5, 5, 5);
		gbc_lblShoppingCart.gridx = 0;
		gbc_lblShoppingCart.gridy = 0;
		add(getLblShoppingCart(), gbc_lblShoppingCart);
		GridBagConstraints gbc_orders = new GridBagConstraints();
		gbc_orders.gridwidth = 4;
		gbc_orders.insets = new Insets(0, 0, 5, 5);
		gbc_orders.fill = GridBagConstraints.BOTH;
		gbc_orders.gridx = 0;
		gbc_orders.gridy = 1;
		add(getOrders(), gbc_orders);
		GridBagConstraints gbc_options = new GridBagConstraints();
		gbc_options.gridwidth = 4;
		gbc_options.insets = new Insets(0, 0, 0, 5);
		gbc_options.fill = GridBagConstraints.BOTH;
		gbc_options.gridx = 0;
		gbc_options.gridy = 2;
		add(getOptions(), gbc_options);
	}

	public JLabel getLblShoppingCart() {
		if (lblShoppingCart == null) {
			lblShoppingCart = new JLabel("Shopping Cart");
			lblShoppingCart.setHorizontalAlignment(SwingConstants.LEFT);
			lblShoppingCart.setFont(new Font("Tahoma", Font.PLAIN, 26));
		}
		return lblShoppingCart;
	}
	public JPanel getOptions() {
		if (options == null) {
			options = new JPanel();
			options.setBackground(Color.LIGHT_GRAY);
			GridBagLayout gbl_options = new GridBagLayout();
			gbl_options.columnWidths = new int[]{125, 131, 0, 128, 0};
			gbl_options.rowHeights = new int[]{56, 0};
			gbl_options.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
			gbl_options.rowWeights = new double[]{0.0, Double.MIN_VALUE};
			options.setLayout(gbl_options);
			GridBagConstraints gbc_lblTotalPrice = new GridBagConstraints();
			gbc_lblTotalPrice.insets = new Insets(0, 0, 0, 5);
			gbc_lblTotalPrice.fill = GridBagConstraints.BOTH;
			gbc_lblTotalPrice.gridx = 0;
			gbc_lblTotalPrice.gridy = 0;
			options.add(getLblTotalPrice(), gbc_lblTotalPrice);
			GridBagConstraints gbc_totalPrice = new GridBagConstraints();
			gbc_totalPrice.insets = new Insets(0, 0, 0, 5);
			gbc_totalPrice.anchor = GridBagConstraints.WEST;
			gbc_totalPrice.fill = GridBagConstraints.BOTH;
			gbc_totalPrice.gridx = 1;
			gbc_totalPrice.gridy = 0;
			options.add(getTotalPrice(), gbc_totalPrice);
			GridBagConstraints gbc_btnCheckout = new GridBagConstraints();
			gbc_btnCheckout.gridx = 3;
			gbc_btnCheckout.gridy = 0;
			options.add(getBtnCheckout(), gbc_btnCheckout);
		}
		return options;
	}
	public JScrollPane getOrders() {
		if (orders == null) {
			orders = new JScrollPane();
			orders.setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.LIGHT_GRAY));
			orders.getViewport().setBackground(Color.GRAY);
			orders.setViewportView(getProducts());
		}
		return orders;
	}
	public JPanel getProducts() {
		if (products == null) {
			products = new JPanel();
		}
		return products;
	}
	public JLabel getLblTotalPrice() {
		if (lblTotalPrice == null) {
			lblTotalPrice = new JLabel("Total Price: $");
			lblTotalPrice.setHorizontalAlignment(SwingConstants.RIGHT);
			lblTotalPrice.setFont(new Font("Segoe UI Light", Font.BOLD, 18));
			lblTotalPrice.setForeground(Color.DARK_GRAY);
		}
		return lblTotalPrice;
	}
	public JLabel getTotalPrice() {
		if (totalPrice == null) {
			totalPrice = new JLabel();
			totalPrice.setForeground(Color.DARK_GRAY);
			totalPrice.setHorizontalAlignment(SwingConstants.LEFT);
			totalPrice.setFont(new Font("Segoe UI", Font.BOLD, 22));
		}
		return totalPrice;
	}
	public JButton getBtnCheckout() {
		if (btnCheckout == null) {
			btnCheckout = new JButton("Checkout");
			btnCheckout.setEnabled(false);
			btnCheckout.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {
					control.checkOut();
				}
			});
		}
		return btnCheckout;
	}
}
